import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2021-05-19
 * Time: 23:19
 */
public class Covid19 {

    String countryName;
    int cases;


    public Covid19(String countryName, int cases) {
        this.countryName = countryName;
        this.cases = cases;
    }

    public static void main(String[] args) {
        ArrayList<Covid19> list = new ArrayList<>();

        System.out.println("Enter data:");
        System.out.println();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            String line = scanner.nextLine();
            if (line.isEmpty()) {
                break;
            }
            String countryName = line.split(" ")[0];
            int cases = Integer.parseInt(line.split(" ")[1]);
            list.add(new Covid19(countryName, cases));
        }

        list.sort((o1, o2) -> Integer.compare(o1.cases, o2.cases));

        for (Covid19 covid19 : list) {
            System.out.println(covid19.countryName);
        }

    }
}
